//
//  UILabelExtension.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/16.
//

import Foundation
import UIKit
private var edgesKey = UInt32(123456)
extension UILabel:CustomMethodSwizzling{
    static func awake() {
        swizzledMethod
    }
    private static let swizzledMethod: ()={
        let oldSelector = #selector(layoutSubviews)
        let newSelector = #selector(customDrawText)
        swizzlingForClass(UILabel.self, oldSelector: oldSelector, newSelector: newSelector)
    }()
    var contentEdges:UIEdgeInsets?{
        set{objc_setAssociatedObject(self, &edgesKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC)}
        get{objc_getAssociatedObject(self, &edgesKey) as? UIEdgeInsets ?? UIEdgeInsets.zero}
    }

    @objc func customDrawText() {
        customDrawText()
        
    }
    
//    open override var intrinsicContentSize: CGSize{
//        var size = super.intrinsicContentSize
//        SystemLog(size)
//        size.width += self.contentEdges!.left
//        size.width += self.contentEdges!.right
//        size.height += self.contentEdges!.top
//        size.height += self.contentEdges!.bottom
//        SystemLog(size)
//        return size
//    }
}

